﻿
@{
    ViewBag.Title = "完善节点商城信息";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    var img_url = ViewBag.img_url;
}
@model shop_info_dto
<body class="page-infor page-completeinfor">

    @*<div class="lt-head">
            <a href="javascript:history.go(-1);">
                <i class="icon-back fn-left"></i>
            </a>
            <span class="center">完善节点商城信息</span>
        </div>*@
    <!--header end-->
    <form name="shop_info" id="shop_info" action="/shopinfo/save" method="post" enctype="multipart/form-data">
        <input type="hidden" id="id" name="id" value="@Model.id" />
        <div class="mod-forms ">
            <div class="ui-item">
                <div class="ui-label">Logo</div>
                <div class="fn-center">
                    <label class="ui-file" for="file">
                        <div class="fileBox">
                            @if (!string.IsNullOrEmpty(Model.shop_logo)) {
                                <i class="icon-file logo_shop  none"></i>
                                <img src="@(img_url+Model.shop_logo)" id="photo" />
                            } else {
                                <i class="icon-file logo_shop "></i>
                                <img src=" " id="photo" style="display:none" />}
                        </div>
                        <p class="fn28">点击上传修改LOGO</p>
                        <input class="j-file" id="upload_shop_logo" type="file" name="upload_shop_logo">
                        <input type="hidden" name="shop_logo" value="@Model.shop_logo" id="shop_logo" />
                    </label>
                </div>
            </div>
            <div class="ui-item">
                <div class="ui-label">背景</div>
                <div class="fn-center">
                    <label class="ui-file ui-file-img" for="file">
                        <div class="fileBox bg_shop @(string.IsNullOrEmpty(Model.shop_background_img)?"":"none")">
                            <i class="icon-file "></i>

                            <p class="fn28">点击上传背景</p>
                        </div>
                        @if (!string.IsNullOrEmpty(Model.shop_background_img)) {
                            <img src="@(img_url+Model.shop_background_img)" id="photo_bg" />
                        } else {
                            <img src=" " id="photo_bg" style="display:none" />
                        }
                        <img src=" " id="photo_bg" style="display:none" />
                        <input class="j-file" name="upload_shop_bg" id="upload_shop_bg" type="file">
                        <input type="hidden" name="shop_background_img" id="shop_background_img" value="@Model.shop_background_img" />
                    </label>
                </div>
            </div>
            <div class="ui-item">
                <div class="ui-label">商城名称</div>
                <div class="ui-hidden">
                    <input class="ui-input j-input" type="text" placeholder="请输入商城名称"
                           value="@Model.shop_name"
                           name="shop_name"
                           onKeyDown="textCounter(shop_name,remLen,10,0);"
                           onKeyUp="textCounter(shop_name,remLen,10,0);">
                    <span class="num">
                        <em class="j-num">0</em>/10
                        <input name="remLen" type="hidden" value="6" size="5" readonly="readonly">
                    </span>
                    <!-- 您还可以输入:<input name="remLen" type="text" value="6" size="5" readonly="readonly">个字符   -->
                </div>
            </div>
            <div class="ui-item">
                <div class="ui-label">商城说明</div>
                <div class="ui-hidden">
                    <textarea class="ui-textarea j-input" type="text" placeholder="请输入商城介绍"
                              name="remark"
                              onKeyDown="textCounter(remark,remLen2,50,1);"
                              onKeyUp="textCounter(remark,remLen2,50,1);"
                              id="remark"
                              cols="30"
                              rows="10">@Model.remark</textarea>
                    <span class="num">
                        <em class="j-num">0</em>/50
                        <input name="remLen2" type="hidden" value="6" size="5" readonly="readonly">
                    </span>
                </div>
            </div>
            <div class="ui-item">
                <div class="ui-label">客服电话</div>
                <div class="ui-hidden">
                    <input class="ui-input" type="text" id="customer_tel " name="customer_tel" placeholder="请输入客服电话" value="@Model.customer_tel">
                </div>
            </div>
            <div class="ui-item">
                <div class="ui-label">商家地址</div>
                <div class="address">
                    <div class="pickerBox">
                        <i class="icon-go"></i>
                        <input class="ui-input" type="text" id="region_name" name="region_name" placeholder="请选择地区" readonly value="@(Model.region_name)">
                        <input id="region_ids" type="hidden" name="region_ids" value="@(Model.province_id>0?Model.province_id:350200),@(Model.city_id>0?Model.city_id:350000),@(Model.area_id>0?Model.area_id:350203)">

                    </div>
                    <textarea class="ui-textarea" name="shop_address" id="shop_address" cols="30" rows="2"
                              placeholder="详细地址：如道路、门牌号、小区、楼栋号、单元室等">@Model.shop_address</textarea>
                </div>
            </div>
            <div class="btnBox">
                <a href="javascript:submitShopInfo()" class="ui-btn-buy">保 存</a>
            </div>
        </div>
    </form>
    <!-- 三级联动 -->
    <script src="~/Scripts/LArea.js"></script>
    <link href="~/Content/css/LArea.css" rel="stylesheet" />
    <script src="~/Scripts/token-common.js"></script>
    <script type="text/javascript">
        $(function () {
            $.get("/user/GetRegion", function (result) {
                if (result.result_code == 1000) {
                    var area1 = new LArea();
                    area1.init({
                        'trigger': '#region_name', //触发选择控件的文本框，同时选择完毕后name属性输出到该位置
                        'valueTo': '#region_ids', //选择完毕后id属性输出到该位置
                        'keys': {
                            id: 'id',
                            name: 'name'
                        }, //绑定数据源相关字段 id对应valueTo的value属性输出 name对应trigger的value属性输出
                        'type': 1, //数据源类型
                        'data': result.data //数据源
                    });
                }
            });


            $("#upload_shop_logo").change(function () {
                if (this.files[0].size.toFixed(1) > 2 * 1024 * 1024) {

                    layer.msg("请选择小于2M的图片");
                    return false;
                }
                var objUrl = getObjectURL(this.files[0]);
                if (objUrl) {
                    $("#photo").attr("src", objUrl).show();
                    $(".logo_shop").addClass("none");
                    $("#shop_logo").val(objUrl);
                }
            })
            $("#upload_shop_bg").change(function () {
                if (this.files[0].size.toFixed(1) > 2 * 1024 * 1024) {

                    layer.msg("请选择小于2M的图片");
                    return false;
                }
                var objUrl = getObjectURL(this.files[0]);
                if (objUrl) {
                    $("#photo_bg").attr("src", objUrl).show();
                    $(".bg_shop").addClass("none");
                    $("#shop_background_img").val(objUrl);
                }
            })

        });
        function textCounter(field, countfield, maxlimit, type) {
            // 函数，3个参数，表单名字，表单域元素名，限制字符；
            if (field.value.length > maxlimit) {
                //如果元素区字符数大于最大字符数，按照最大字符数截断；
                field.value = field.value.substring(0, maxlimit);
            }
            else {
                //在记数区文本框内显示剩余的字符数；
                var numText = field.value.length;
                var dom = document.getElementsByClassName('j-num')[type].innerHTML = numText;
            }
        }
        $('.j-num').each(function () {
            var valLen = $(this).parent('.num').siblings('.j-input').val().length;
            $(this).text(valLen);
        });
        function submitShopInfo() {

            layer.confirm('您确定保存么', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                $("#shop_info").ajaxSubmit(function (result) {
                    if (result.result_code == 1000) {
                        layer.msg(result.result_msg);
                        setTimeout(function () { window.location.href = '/shopinfo/shopmanage'; }, 1500);
                    } else {
                        layer.msg(result.result_msg);
                    }
                });
            }, function () {

            });

        }
    </script>
</body>

